package com.poems.util;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;



/**
 * 五言绝句（平仄）音调检测
 * @author hqz
 *
 */
public class DetectFiveRhymeAndTones extends PoemsLiberary{
	
	/**
	 * 中华新韵
	 * @param poem
	 * @return poemsFormat[]
	 */
	public String[] Zhxy(String poem){
	  String[] poems = Util.delspecialsign(poem).split("");
	  String[] poemsFormat = new String[21] ;
	  for(int i = 1;i<poems.length;i++){
	  		int ping = 0;
		    int ze = 0;
	  	for(Entry<String, Object> value : zhxy.entrySet()){
				if(value.getValue().toString().contains(poems[i])){
					if(value.getKey().indexOf("平") > 1){
						ping++;
					}
					if(value.getKey().indexOf("仄") > 1){
						ze++;
					}

				}
			}
	  	 if(ping > 0 && ze == 0){
			 poemsFormat[i] = "平";
	     }
	     if(ze > 0 && ping == 0){
	    	 poemsFormat[i] = "仄";
	     }
	     if(ping > 0 && ze > 0){
	    	 poemsFormat[i] = "v";
	     }
	  	}
	  	return poemsFormat;
		}

	
	/**
	 * 平水韵
	 * @param poem
	 * @return poemsFormat[]
	 */
	public String[] Psy(String poem){
	    String[] poems = Util.delspecialsign(poem).split("");
	    String[] poemsFormat = new String[21] ;
	    for(int i = 1;i<poems.length;i++){
	    	int ping = 0;
	  	    int ze = 0;
	    	for(Entry<String, Object> value : psy.entrySet()){
				if(value.getValue().toString().contains(poems[i])){
					if(value.getKey().indexOf("平") > 1){
						ping++;
					}
					if(value.getKey().indexOf("仄") > 1){
						ze++;
					}
				}
			}
	    	
	    	 if(ping > 0 && ze == 0){
				 poemsFormat[i] = "平";
	         }
	         if(ze > 0 && ping == 0){
	        	 poemsFormat[i] = "仄";
	         }
	         if(ping > 0 && ze > 0){
	        	 poemsFormat[i] = "v";
	         }
	    	
	    }
	    return poemsFormat;
		
	    }
	
	/**
	 * 词林正韵
	 * @param poem
	 * @return poemsFormat
	 */
	public String[] Clzy(String poem){
	    String[] poems = Util.delspecialsign(poem).split("");
	    String[] poemsFormat = new String[21] ;
	    for(int i = 1;i<poems.length;i++){
	    	int ping = 0;
	  	    int ze = 0;
	    	for(Entry<String, Object> value : clzy.entrySet()){
				if(value.getValue().toString().contains(poems[i])){
					if(value.getKey().indexOf("平") > 1){
						ping++;
					}
					if(value.getKey().indexOf("仄") > 1){
						ze++;
					}
					if(value.getKey().indexOf("入") > 1){
						ze++;
					}
				}
			}
	    	
			 if(ping > 0 && ze == 0){
				 poemsFormat[i] = "平";
	         }
	         if(ze > 0 && ping == 0){
	        	 poemsFormat[i] = "仄";
	         }
	         if(ping > 0 && ze > 0){
	        	 poemsFormat[i] = "v";
	         }	
	    }
	    return poemsFormat;
	}
	
}
